package day3;

import java.util.*;

/**
 * @author oldliu
 * @since 1.0
 */
public class MapTest {
    public static void main(String[] args) {
        //键值对
        //HashMap.TreeMap...
        Map map = new HashMap();

        map.put("狗", "dog");
        map.put("小狗", "dog");
        map.put("猫", "cat");
        map.put("cow", "牛");
        map.put("猫", "喵苗");
        map.put("没有", null);
        map.put(null, null);
        System.out.println(map.size());
        System.out.println(map);
        //
        //map.keySet();//获得所有的 key.Set
        //map.values();//获得所有的value.Collection
        Scanner in = new Scanner(System.in);
        System.out.println("请输入一个单词：");
        String my = in.next();

        if (map.containsKey(my)) {
            String str = (String) map.get(my);
            System.out.println(str);
        } else
            System.out.println("没有，不在其中。。。");
//        String str = (String) map.get(my);
//        if (str == null) {
//            System.out.println("没有");
//        } else
//            System.out.println(str);
        System.out.println(">>>>>>>>>>>>>>>>迭代>>>>>>>1>>>>>>>>>>");
        Set set = map.keySet();
        Iterator ir = set.iterator();
        while (ir.hasNext()) {
            Object key = ir.next();//每一个key
            Object value = map.get(key);
            System.out.println(key + "=" + value);
        }
        System.out.println(">>>>>>>>>>>>>>>>迭代>>>>>>>2>>>>>>>>>>");

        Set<Map.Entry> s2 = map.entrySet();
        Iterator<Map.Entry> ir2 = s2.iterator();
        while (ir2.hasNext()) {
            Map.Entry next = ir2.next();
            System.out.println(next.getKey() + "===" + next.getValue());
        }
    }
}
